package com.xsm.takephoto;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

public class getBitmap {
	static Activity context;
	static Uri uri=null;
	public getBitmap(Activity context,Uri uri){
		this.context=context;
		this.uri=uri;
	}
	
	public getBitmap(Activity context){
		this.context=context;
	}
	
public Bitmap get(){
   return lessenUriImage();
}

public static String getPath()  
{    
   String[] projection = {MediaStore.Images.Media.DATA };    
   Cursor cursor = context.managedQuery(uri, projection, null, null, null);    
   int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);    
   cursor.moveToFirst();  
   return cursor.getString(column_index);    
} 

public final static Bitmap lessenUriImage()
{ 
String path=getPath();	
 Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inJustDecodeBounds =false;
bitmap=BitmapFactory.decodeFile(path,options); 
bitmap=maxtrixBitmap(bitmap);
return bitmap;
}

public static Bitmap maxtrixBitmap(Bitmap bitmap){
	 if(bitmap==null)
		 return bitmap;
	int w=bitmap.getWidth();
	int h=bitmap.getHeight();
	float scaleWidth = ((float) 120)/w;
	float scaleHeight = ((float) 120)/h;
	Matrix matrix = new Matrix();
	matrix.postScale(scaleWidth, scaleHeight);
	Bitmap newbm = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
	 return newbm;
}

}
